//
//  ViewController.m
//  Target-Action
//
//  Created by apple on 15/9/12.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import "ViewController.h"
#import "CustomButton.h"
#import "CustomView.h"


@interface ViewController ()

{
    CustomView *_customView;
    
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
#if 0
    //1、UICtrol的子类常常通过Target- Action模式获取用户的操作；
    
    //2、下面使用Target-Action模式将CustomButton的点击事件传递到目标对象中；
    
    //3、UIControl封装了许多类型的用户事件；
    
    
    CustomButton *customButton = [[CustomButton alloc] initWithFrame:CGRectMake(20, 20, 100, 40)];
    
    customButton.backgroundColor = [UIColor greenColor];
    
    [customButton addTarget:self action:@selector(didClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:customButton];
    
#endif
    
    
#if 1
    
    _customView = [[CustomView alloc] initWithFrame:CGRectMake(40, 40, 200, 40)];
    
    _customView.backgroundColor = [UIColor greenColor];
    
    _customView.title = @"保存";
    
    _customView.touchUpInside = ^(CustomView *sender)
    {
    
        NSLog(@"点击按钮！");
    };
    
    [self.view addSubview:_customView];
    
    
    
#endif
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didClicked:(CustomButton *)sender
{
    NSLog(@"就是干");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
